{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="店铺名/手机号"/>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="faceSerialNo" lay-search="">
                                <option  value="">不限</option>
                                <option  value="1">刷脸商户</option>
                            </select>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.shop_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <script type="text/html" id="QRCodeTpl">
                        {{# if(d.shop_qr_code){ }}
                        <img src="{{d.shop_qr_code}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        <input type="checkbox" value="{{d.shop_id}}"  lay-skin="switch"  lay-text="正常|冻结" lay-filter="OnOff"{{ d.shop_status == 1 ? 'checked' : '' }}  >
                    </script>
                    <script type="text/html" id="nativeBar">
                        <input type="checkbox" value="{{d.shop_id}}"  lay-skin="switch"  lay-text="加入|取消" lay-filter="OnOff1"{{ d.shop_native == 1 ? 'checked' : '' }}  >
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        {{# if(!d.shop_son){ }}
                        <a href="javascript:;" onclick="wk.href('{:url('addSon')}?id={{d.shop_id}}');"  class="btn btn-primary btn-xs m-r-xs" >添加子账号</a>
                        {{# }else{ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.shop_id}}','{:url('sonDel')}')" class="btn btn-danger btn-xs m-r-xs" >删除子账号</a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.href('{:url('recordList')}?id={{d.shop_id}}')" class="btn btn-info btn-xs m-r-xs" >收款记录</a>
                        <a href="javascript:;" onclick="wk.layer_show('设置二级商户号', '{:url('setMch')}?shop_id={{d.shop_id}}&mch_id={{d.sc_mch_id}}')" class="btn btn-warning btn-xs m-r-xs" title="设置二级商户号">设置商户号</a>
                    </script>
                    <script type="text/html" id="ratio">
                        <a href="javascript:;" onclick="wk.href('{:url('ratio')}?id={{d.shop_id}}');"  class="btn btn-primary btn-xs m-r-xs" >赠送比例</a>
                    </script>
                    <script type="text/html" id="imgTpl1">
                        <img src="{{d.shop_hand_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("shop/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: 10
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'shop_name', width: '', title: '店铺名', align: 'center'}
                , {field: 'shop_img', width: 90, title: '头像', align: 'center', templet: '#imgTpl'}
                , {field: 'shop_qr_code', width: 90, title: '收款码', align: 'center', templet: '#QRCodeTpl'}
                , {field: 'shop_contact', width: '', title: '手机号', align: 'center'}
                , {field: 'sheng', width: '', title: '省', align: 'center'}
                , {field: 'shi', width: '', title: '市', align: 'center'}
                , {field: 'qu', width: '', title: '区', align: 'center'}
                , {field: 'shop_address', width: '', title: '地址', align: 'center'}
                , {field: 'username', width: '', title: '上级代理', align: 'center'}
                , {field: 'shop_all_balance', width: '', title: '成交总额', align: 'center'}
                , {field: 'shop_balance', width: '', title: '账户余额', align: 'center'}
                , {field: 'shop_balance_yet', width: '', title: '未确认余额', align: 'center'}
                , {field: 'shop_pledge_money', width: '', title: '商户押金', align: 'center'}
                , {field: 'shop_integral', width: '', title: '积分数量', align: 'center'}
                , {field: 'shop_son', width: '', title: '子账号', align: 'center'}
                , {field: 'shop_son_password', width: '', title: '子账号密码', align: 'center'}
                , {field: 'sc_mch_id', width: '', title: '商户号', align: 'center'}
                , {field: 'shop_hand_img', width: '', title: '营业执照', align: 'center', toolbar: '#imgTpl1'}
                , {field: 'shop_native',fixed: 'right', width: 100, title: '本地服务',sort: true, align: 'center', templet: '#nativeBar'}
                , {field: 'user_status',fixed: 'right', width: 100, title: '状态',sort: true, align: 'center', templet: '#staBar'}
                , {field: 'shop_ratio',fixed: 'right', width: 100, title: '赠送比例', align: 'center', templet: '#ratio'}
                , {fixed: 'right', width: 280, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]],
            done:function () {
                $(".table-img").viewer();
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("shopStatus")}',obj);
        });
        //监听状态开关操作
        form.on('switch(OnOff1)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("shopStatus1")}',obj);
        });
    });

    function son(shop_id) {
        layer.prompt({
            formType: 2,
            title: '填写子账号',
            area: ['200px', '50px'],
            btn: ['确认', '取消'],
            maxlength:11,
        },function(value, index, elem){
            var pattern = /^1[34578]\d{9}$/;
            if(!pattern.test(value)){
                wk.error('请填写正确的手机号');
                return;
            }
            send(shop_id,value);
            layer.close(index);
        });
    }
    function send(shop_id,value){
        $.ajax({
            url: "{:url('addSon')}",
            type: "post",
            dataType: "json",
            data: {shop_id:shop_id,value:value},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>